Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --scalar flag to CLI #280

Merged
merged 2 commits into from
Nov 2, 2024
Merged

Add --scalar flag to CLI #280

merged 2 commits into from
Nov 2, 2024

Conversation

mahmoud
Copy link
Owner

@mahmoud mahmoud commented Dec 18, 2023

I was using glom in a script this week, specifically to extract single values from API calls. I noticed I kept having to trim the quotes and whitespace off of the JSON output, because even when it's a single value, it's quoted and followed by a newline.

So this feature strips the quotes and whitespace when passed a new flag: --scalar. This is only done when the glom result is not a collection. If it is, it falls back to normal json output.

Some items to consider:

  1. Name?
    • I have SQLAlchemy 2.0 on the brain and scalar is everywhere. But also boltons has an is_scalar function that maps exactly to this, so even if it's jargon-y, I think it's accurate.
  2. Should it be an error if the output is not a single value?
    • I think for my use case the ergonomics would be worse.
  3. Right now, output is always json. Would it be better to do --output "json"|"scalar"?
    • Kinda don't want to get into the business of emitting yaml, etc.?

None of these are blockers, I am good to merge as is.

Copy link

codecov bot commented Dec 18, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.16%. Comparing base (2e0c552) to head (2a12b5d).
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #280      +/-   ##
==========================================
+ Coverage   98.05%   98.16%   +0.11%     
==========================================
  Files          27       27              
  Lines        4362     4371       +9     
  Branches      765      611     -154     
==========================================
+ Hits         4277     4291      +14     
  Misses         54       54              
+ Partials       31       26       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mahmoud mahmoud merged commit 24c21dc into master Nov 2, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant